﻿using Engine;
using Game;
using Mekiasm.Common;
namespace Mekiasm
{
    public class ElectricDigtal : ComplexModelItem
    {
        public static int Index;
        public ElectricDigtal() : base(new ModelItem[] {
            new ModelItem("cube.011", "ElectricDigtal/front"), new ModelItem("cube.010", "ElectricDigtal/front"),
            new ModelItem("cube.009", "ElectricDigtal/front"), new ModelItem("cube.008", "ElectricDigtal/front"),
            new ModelItem("cube.007", "ElectricDigtal/front"), new ModelItem("cube.006", "ElectricDigtal/front"),
            new ModelItem("cube.005", "ElectricDigtal/front"), new ModelItem("cube.004", "ElectricDigtal/front"),
            new ModelItem("cube.003", "ElectricDigtal/front"), new ModelItem("cube.002", "ElectricDigtal/front"),
            new ModelItem("cube.001", "ElectricDigtal/front"), new ModelItem("cube.000", "ElectricDigtal/front"),
            new ModelItem("cube", "ElectricDigtal/front") }, "ElectricDigtal", "数字型挖矿机")
        {
            
        }
        public override MekBlock.DeviceType GetDeviceType()
        {
            return MekBlock.DeviceType.Electric;
        }
        public override bool OnUse(Ray3 aim, ComponentMiner componentMiner, TerrainRaycastResult? raycast)
        {
            return false;
        }
        public override void OnBlockAdded(SubsystemBlockBehavior blockBehavior, int value, int oldValue, int x, int y, int z)
        {
            ILibrary.AddBaseEnergyEntity(DisplayName, x, y, z, null, ILibrary.GetRotetedConfig(value, new MachineFaceConfig[] {
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric),
            new MachineFaceConfig(MekBlock.MachineMode.IN,MekBlock.DeviceType.Electric)
            }));
            ElectricSystem.Add(new ElectricElement.ElectricDigtalElement(x, y, z));
        }
        public override void OnBlockGenerated(int value, int x, int y, int z, bool isLoaded)
        {
            ElectricSystem.Add(new ElectricElement.ElectricDigtalElement(x, y, z));
        }
        public override void OnBlockRemoved(SubsystemBlockBehavior blockBehavior, int value, int newValue, int x, int y, int z)
        {
            ElectricSystem.Remove(new Point3(x, y, z));
            ILibrary.RemoveBlockEntity(x, y, z);
        }
        public override bool OnInteract(SubsystemBlockBehavior blockBehavior, TerrainRaycastResult raycastResult, ComponentMiner componentMiner)
        {
            ComponentElectricDigtal digtal = ILibrary.SubsystemBlockEntities.GetBlockEntity(raycastResult.CellFace.X, raycastResult.CellFace.Y, raycastResult.CellFace.Z).Entity.FindComponent<ComponentElectricDigtal>();
            componentMiner.ComponentPlayer.ComponentGui.ModalPanelWidget = new ElectricDigtalWidget(digtal, componentMiner);
            return true;
        }

    }
}
